/*******************************************************************************
  * @File           include.c
  * @Encoding       UTF8
  * @Author         SL400
  * @Version        V1.0.0
  * @Brief          
*******************************************************************************/

#ifndef _BASE_INCLUDE_H_
#define _BASE_INCLUDE_H_

#include <string.h>
#include <stdio.h>
#include <api_os.h>
#include <api_event.h>
#include <api_debug.h>
#include <api_hal_uart.h>
#include <api_inc_time.h>

#define GNSS_DEBUG_EN     (1)
#define GNSS_TRACE_LEVEL  (1)

#define MEDIA_DEBUG_EN    (1)
#define MEDIA_TRACE_LEVEL (1)

#define GPRS_DEBUG_EN     (1)
#define GPRS_TRACE_LEVEL  (1)

// 定义GNSS模块调试打印
#if (GNSS_DEBUG_EN == 1)
#define GNSS_DEBUG(fmt,...)  \
    do \
    { \
        Trace(GNSS_TRACE_LEVEL, "[GNSS][%s][%s][%d]>>"#fmt,__FILE__,__FUNCTION__,__LINE__,##__VA_ARGS__); \
    } while(0)

#define GNSS_DEBUG_MEM(a,b,c) \
    do \
    { \
        Trace(GNSS_TRACE_LEVEL, "[GNSS][%s][%s][%d]>>Trace Memory",__FILE__,__FUNCTION__,__LINE__); \
        Trace_MemBlock(GNSS_TRACE_LEVEL,a,b,c); \
    } while(0)
#else
#define GNSS_DEBUG(fmt,...)   
#define GNSS_DEBUG_MEM(a,b,c) 
#endif

// 定义MEDIA模块调试打印
#if (MEDIA_DEBUG_EN == 1)
#define MEDIA_DEBUG(fmt,...)  \
    do \
    { \
        Trace(MEDIA_TRACE_LEVEL, "[MEDIA][%s][%s][%d]>>"#fmt,__FILE__,__FUNCTION__,__LINE__,##__VA_ARGS__); \
    } while(0)

#define MEDIA_DEBUG_MEM(a,b,c) \
    do \
    { \
        Trace(MEDIA_TRACE_LEVEL, "[MEDIA][%s][%s][%d]>>Trace Memory",__FILE__,__FUNCTION__,__LINE__); \
        Trace_MemBlock(MEDIA_TRACE_LEVEL,a,b,c); \
    } while(0)
#else
#define MEDIA_DEBUG(fmt,...)   
#define MEDIA_DEBUG_MEM(a,b,c) 
#endif

// 定义GPRS模块调试打印
#if (GPRS_DEBUG_EN == 1)
#define GPRS_DEBUG(fmt,...)  \
    do \
    { \
        Trace(GPRS_TRACE_LEVEL, "[GPRS][%s][%s][%d]>>"#fmt,__FILE__,__FUNCTION__,__LINE__,##__VA_ARGS__); \
    } while(0)

#define GPRS_DEBUG_MEM(a,b,c) \
    do \
    { \
        Trace(GPRS_TRACE_LEVEL, "[GPRS][%s][%s][%d]>>Trace Memory",__FILE__,__FUNCTION__,__LINE__); \
        Trace_MemBlock(GPRS_TRACE_LEVEL,a,b,c); \
    } while(0)
#else
#define GPRS_DEBUG(fmt,...)   
#define GPRS_DEBUG_MEM(a,b,c) 
#endif

extern HANDLE MainTaskHandle;
extern HANDLE GnssTaskHandle;
extern HANDLE MediaTaskHandle;
extern HANDLE GprsTaskHandle;
extern HANDLE UiTaskHandle;

enum {
    kMainTaskPriority,
    kGPRSTaskPriority,
    kGpsTaskPriority,
    kFileTaskPriority,
    kUiTaskPriority,
};

// 主任务
#define MAIN_TASK_STACK_SIZE    (2048 * 2)
#define MAIN_TASK_PRIORITY      kMainTaskPriority
#define MAIN_TASK_NAME          "Main Task"

// GPS任务
#define GPS_TASK_STACK_SIZE     (2048 * 2)
#define GPS_TASK_PRIORITY       kGpsTaskPriority
#define GPS_TASK_NAME           "GPS Task"

// GPRS任务
#define GPRS_TASK_STACK_SIZE    (2048 * 2)
#define GPRS_TASK_PRIORITY      kGPRSTaskPriority
#define GPRS_TASK_NAME          "GPRS Task"

// File任务
#define MEDIA_TASK_STACK_SIZE    (2048 * 2)
#define MEDIA_TASK_PRIORITY      kFileTaskPriority
#define MEDIA_TASK_NAME          "File Task"

// UI任务
#define UI_TASK_STACK_SIZE      (2048 * 2)
#define UI_TASK_PRIORITY        kUiTaskPriority
#define UI_TASK_NAME            "UI Task"

typedef struct _SysTime_t{
    uint8_t  Hour;
    uint8_t  Minute;
    uint8_t  Second;
    uint8_t  Day;
    uint8_t  Month;
    uint8_t  WDay; // Day of week
    uint16_t Year; // 00 ~ 99
    uint16_t Milliseconds;
} SysTime_t;

// GNSS 事件相关
typedef enum {
    kGnssEventNmeaReveived = 0, // GNSS 消息
    kGnssEventMax   
} Gnss_Event_ID_t;

typedef struct _GnssEvent_t {
    Gnss_Event_ID_t EventId;
    void*           EventData; 
} GnssEvent_t;

#endif /* end of _BASE_INCLUDE_H_ */
